$(function(){
    var idRotina = $('#idRotina').val();
    jQuery("#gridResultado").jqGrid({
        caption: "Visualização de Resultado",
        url: "intranet/Resultado/grid/id/"+idRotina,
        datatype: "json",
        colNames:['Exame', 'Tipo Resultado', 'Metodologia', 'Kit Sorológico'],
        colModel:[
            {name:'nome', index:'nome', width:180, align:"center"},
            {name:'resultado', index: 'resultado', width: 110, align: 'center', search:false},
            {name:'metodologia', index:'metodologia', width:300, align:"center", search:false},
            {name:'kitSorologia', index:'kitSorologia', width:340, align:"center", search:false}
        ],
        //rowNum: 10,
        //rowList: [10,20,30,50,100],
        width: "100%",
        height: 250,
        pager: '#navResultado',
        sortname: "idExame",
        sortorder: "ASC",
        multiselect: false,
        viewrecords: true,
        loadonce:true,
        scroll:true,//************************************
        ignoreCase:true,//a pesquisa deixa de ser case sensitive
        subGrid: true,
        subGridRowExpanded: function(subgrid_id, row_id) {
            var subgrid_table_id;
            var pager_id;
            subgrid_table_id = subgrid_id+"_t";
            pager_id = "p_"+subgrid_table_id;
            $("#"+subgrid_id).html("<table id='"+subgrid_table_id+"' class='scroll'></table><div id='"+pager_id+"' class='scroll'></div>");
            jQuery("#"+subgrid_table_id).jqGrid({
                url:'intranet/Resultado/subgrid/row_id/'+row_id+'/idRotina/'+idRotina,
                datatype: 'json',
                colNames: ['Amostra', 'Inicial','Resposta', 'Valor 1', 'Valor 2'],
                colModel: [
                    {name: 'idAmostra', index: 'idAmostra', width: 150, align: 'center'},
                    {name: 'inicial', index: 'inicial', width: 100, align: 'center'},
                    {name: 'resposta', index: 'resposta', width: 180, align: 'center'},
                    {name: 'valor1', index: 'valor1', width: 220, align: 'center', search:false},
                    {name: 'valor2', index: 'valor2', width: 220, align: 'center', search:false}
                ],
                //rowNum: 10,
                pager: pager_id,
                height: "100%",
                sortname: "idAmostra",
                sortorder: "ASC",
                //rowList: [10,20,30,50,100],
                viewrecords: true,
                scroll:true,
                loadonce:true
            });
            jQuery("#"+subgrid_table_id).jqGrid('navGrid',"#"+pager_id,{edit:false,add:false,del:false, search:false})
            jQuery("#"+subgrid_table_id).jqGrid('filterToolbar',{stringResult:true, searchOnEnter:false});
        }
    })
    .navGrid("#navResultado",{
        edit: false, //Ativar/Desativar bot�o de Edi��o
        add: false, //Ativar/Desativar bot�o de Adi��o
        del: false, //Ativar/Desativar bot�o delete
        search: false, //Ativar/Desativar bot�o de busca
        view: false, //Ativar/Desativar bot�o de visualiza��o dos registros
        refresh: true //Ativar/Desativar bot�o refresh
    })
    .navButtonAdd('#navResultado',{
        caption:"Voltar", 
        //buttonicon:"ui-icon-add", 
        onClickButton: function(){ 
            intranet.carregaModulo('intranet/resultado/index/');
        }, 
        position:"last"
    });
});
jQuery("#gridResultado").jqGrid('navGrid','#navResultado',{edit:false,add:false,del:false, search:false});
jQuery("#gridResultado").jqGrid('filterToolbar',{stringResult:true, searchOnEnter:false});
